package com.lphl.pet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lphl.pet.GloableParams;
import com.lphl.pet.MyApplication;
import com.lphl.pet.R;

import java.io.File;
import java.util.List;

/**
 * Created by Administrator on 2015/7/24.
 */
public class PicListAdapter extends BaseAdapter {

    private Context ctx;
    private List<String> picList;

    public PicListAdapter(Context ctx, List<String> picList){
        this.ctx = ctx;
        this.picList = picList;
    }

    @Override
    public int getCount() {
        return picList.size();
    }

    @Override
    public String getItem(int position) {
        return picList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(ctx, R.layout.item_list_app, null);
            new ViewHolder(convertView);
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        String path = GloableParams.SDCardPath + picList.get(position);
        File file = new File(path);
        MyApplication.initImageLoader(ctx).displayImage(path, holder.iv_icon);
        holder.tv_name.setText(file.getName());
        return convertView;
    }

    class ViewHolder {
        ImageView iv_icon;
        TextView tv_name;

        public ViewHolder(View view) {
            iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            view.setTag(this);
        }
    }
}